from gevent import monkey
monkey.patch_all()
import leancloud
import os
from main import app
from requests.packages.urllib3.util.ssl_ import create_urllib3_context
leancloud.init(os.environ['LEANCLOUD_APP_ID'],os.environ['LEANCLOUD_APP_KEY'] )
engine=leancloud.Engine(app)
create_urllib3_context()
application = engine
if __name__ == '__main__':
    # 只在本地开发环境执行的代码
    from gevent.pywsgi import WSGIServer
    from werkzeug.serving import run_with_reloader
    from werkzeug.debug import DebuggedApplication

    @run_with_reloader
    def run():
        global application
        app.debug = True
        application = DebuggedApplication(application, evalex=True)
        server = WSGIServer(('0.0.0.0', int(os.environ['LEANCLOUD_APP_PORT'])), application)
        server.serve_forever()

    run()